#include"Ring.hpp"
void* producer(void* arg)
{
    circular_queue<int> *ring_buffer = static_cast<circular_queue<int>*>(arg);
    int data = 0;
    while(true){
        ring_buffer->push(data);
        std::cout<<"生产了一个数据: "<<data<<std::endl;
        data++;
    }
}
void* consumer(void* arg)
{
    circular_queue<int> *ring_buffer = static_cast<circular_queue<int>*>(arg);
    while(true){
        sleep(2);
        int data;
        ring_buffer->pop(&data);
        std::cout<<"消费了一个数据: "<<data<<std::endl;
    }
}

int main(int argc, char *argv[])
{
    circular_queue<int> *ring_buffer = new circular_queue<int>();
    pthread_t consumer_tid, producer_tid;//生产者消费者线程
    pthread_create(&consumer_tid, nullptr, consumer, ring_buffer);
    pthread_create(&producer_tid, nullptr, producer, ring_buffer);

    pthread_join(consumer_tid, nullptr);
    pthread_join(producer_tid, nullptr);
    delete ring_buffer;
    return 0;
}